﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.DocText"/>.
    /// </summary>
    public class DocTextVM : DocCommentVM
    {
        #region /* STATICS */

        internal static new void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(DocText),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new DocTextVM((DocText)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.DocText"/>.
        /// </summary>
        public DocTextVM(DocText docText, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(docText, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.DocText"/> model.
        /// </summary>
        public DocText DocText
        {
            get { return (DocText)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        protected override void RenderContent(CodeRenderer renderer, TextStyle textStyle, RenderFlags flags)
        {
            RenderText(renderer, (string)DocText.Content, textStyle | TextStyle.NoCache, flags, this);
        }

        public static void RenderText(CodeRenderer renderer, string text, TextStyle textStyle, RenderFlags flags, DocCommentVM tag)
        {
            string[] lines = text.Split('\n');
            for (int i = 0; i < lines.Length; ++i)
            {
                if (i > 0)
                    RenderDocNewLines(renderer, 1, flags, tag);
                if (lines[i].Length > 0)
                    renderer.RenderText(lines[i], COMMENT_BRUSH, (UseProportionalFont ? textStyle | TextStyle.Proportional : textStyle), tag);
            }
        }

        #endregion
    }
}
